// const app = getApp();
// Page({
//   data: {
//     StatusBar: app.globalData.StatusBar,
//     CustomBar: app.globalData.CustomBar,
//     hidden: true,
//     plist: [
//       {
//         id: 0,
//         name: '六号公寓',
//         des:'',
//         code:'12345'
//       },
//      {
//         id: 1,
//         name: '尤里广场'
//       },
//       {
//         id: 2,
//         name: '第四餐厅'
//       },
//       {
//         id: 3,
//         name: '博大花园'
//       },
//       {
//         id: 4,
//         name: '三号公寓'
//       }
//     ],
//   },
//   onLoad() {
//     let list = []
//     for(let i in this.data.plist){
//       list.push({ label: this.data.plist[i]})
//     }
//     this.setData({
//       list
//     })
//     console.log(list)
//     let clist = [];
//     for (let i = 0; i < 26; i++) {
//       clist[i] = String.fromCharCode(65 + i)
//     }
//     this.setData({
//       clist: clist,
//       listCur: clist[0]
//     })
//   },
//   onReady() {
//     let that = this;
//     wx.createSelectorQuery().select('.indexBar-box').boundingClientRect(function(res) {
//       that.setData({
//         boxTop: res.top
//       })
//     }).exec();
//     wx.createSelectorQuery().select('.indexes').boundingClientRect(function(res) {
//       that.setData({
//         barTop: res.top
//       })
//     }).exec()
//   },
//   //获取文字信息
//   getCur(e) {
//     this.setData({
//       hidden: false,
//       listCur: this.data.list[e.target.id],
//     })
//   },

//   setCur(e) {
//     this.setData({
//       hidden: true,
//       listCur: this.data.listCur
//     })
//   },
//   //滑动选择Item
//   tMove(e) {
//     let y = e.touches[0].clientY,
//       offsettop = this.data.boxTop,
//       that = this;
//     //判断选择区域,只有在选择区才会生效
//     if (y > offsettop) {
//       let num = parseInt((y - offsettop) / 20);
//       this.setData({
//         listCur: that.data.list[num]
//       })
//     };
//   },

//   //触发全部开始选择
//   tStart() {
//     this.setData({
//       hidden: false
//     })
//   },

//   //触发结束选择
//   tEnd() {
//     this.setData({
//       hidden: true,
//       listCurID: this.data.listCur
//     })
//   },
//   indexSelect(e) {
//     let that = this;
//     let barHeight = this.data.barHeight;
//     let list = this.data.list;
//     let scrollY = Math.ceil(list.length * e.detail.y / barHeight);
//     for (let i = 0; i < list.length; i++) {
//       if (scrollY < i + 1) {
//         that.setData({
//           listCur: list[i],
//           movableY: i * 20
//         })
//         return false
//       }
//     }
//   }
// });
const app = getApp()
Page({
  data: {
    StatusBar: app.globalData.StatusBar,
    CustomBar: app.globalData.CustomBar,
    Custom: app.globalData.Custom,
    TabCur: 0,
    MainCur: 0,
    VerticalNavTop: 0,
    list: [],
    img: [
      "https://z3.ax1x.com/2021/05/30/2Vmaef.png",
      "https://z3.ax1x.com/2021/05/30/2VmQoD.png"
    ],
    psite: [{
        index: 0,
        sitename: '六号公寓'
      },
      {
        index: 1,
        sitename: '尤里广场'
      },
      {
        index: 2,
        sitename: '第四餐厅'
      },
      {
        index: 3,
        sitename: '二十号楼'
      },
      {
        index: 13,
        sitename: '一号公寓'
      },
      {
        index: 12,
        sitename: '四号公寓'
      },
      {
        index: 4,
        sitename: '三教东侧'
      },
      {
        index: 5,
        sitename: '博大花园'
      },
      {
        index: 6,
        sitename: '邮政北侧'
      },
      {
        index: 7,
        sitename: '大红炉东'
      },
      {
        index: 8,
        sitename: '第三餐厅'
      }, 
      {
        index: 9,
        sitename: '东校9号'
      },  
      {
        index: 10,
        sitename: '东校3教'
      },  

    ],
    plist: [{
        id: 0,
        site: '六号公寓',
        name: '1号站',
        des: '六号楼北-北侧主机',
        code: 'CDZ0533LG0500'
      },
      {
        id: 1,
        site: '六号公寓',
        name: '2号站',
        des: '六号楼北-南侧主机',
        code: 'CDZ0533LG0400'
      },
      {
        id: 2,
        site: '六号公寓',
        name: '3号站',
        des: '六号楼北-西侧主机',
        code: 'CDZ0533LG1400'
      },
      {
        id: 3,
        site: '尤里广场',
        name: '1号站',
        des: '营业厅西-最北侧主机',
        code: 'CDZ0533LG2100'
      },
      {
        id: 4,
        site: '尤里广场',
        name: '2号站',
        des: '营业厅西-中间主机',
        code: 'CDZ0533LG2200'
      },
      {
        id: 5,
        site: '尤里广场',
        name: '3号站',
        des: '营业厅西-最南侧主机',
        code: 'CDZ0533LG2300'
      },
      {
        id: 6,
        site: '第四餐厅',
        name: '1号站',
        des: '四餐北侧-主机',
        code: 'CDZ0533LG1500'
      },
      {
        id: 7,
        site: '二十号楼',
        name: '1号站',
        des: '20号公寓东侧-主机',
        code: 'CDZ0533LG0600'
      },
      {
        id: 8,
        site: '三教东侧',
        name: '1号站',
        des: '三教东南角-主机',
        code: 'CDZ0533LG1700'
      },
      {
        id: 9,
        site: '博大花园',
        name: '1号站',
        des: '农行对过-主机',
        code: 'CDZ0533LG0700'
      },
      {
        id: 10,
        site: '邮政北侧',
        name: '1号站',
        des: '第一浴室门口-主机',
        code: 'CDZ0533LG0300'
      },
      {
        id: 11,
        site: '大红炉东',
        name: '1号站',
        des: '大红炉东侧靠近东门-主机',
        code: 'CDZ0533LG1600'
      },
      {
        id: 12,
        site: '第三餐厅',
        name: '1号站',
        des: '三餐东南角-东侧主机',
        code: 'CDZ0533LG1300'
      },
      {
        id: 11,
        site: '第三餐厅',
        name: '2号站',
        des: '三餐东南角-西侧主机',
        code: 'CDZ0533LG1200'
      },
      {
        id: 12,
        site: '东校9号',
        name: '1号站',
        des: '东校九号宿舍楼旁边主机',
        code: 'CDZ0533LG1100'
      },
      {
        id: 13,
        site: '东校3教',
        name: '1号站',
        des: '东校三教旁边主机',
        code: 'CDZ0533LG2000'
      },
      {
        id: 14,
        site: '四号公寓',
        name: '1号站',
        des: '四号公寓西侧-主机',
        code: 'CDZ0533LG0100'
      },
      {
        id: 15,
        site: '一号公寓',
        name: '1号站',
        des: '一号公寓区域-主机',
        code: 'CDZ0533LG0200'
      },

    ],
    load: true
  },
  onLoad() {
    wx.showLoading({
      title: '加载中...',
      mask: true
    });
    let site = []
    for (let n in this.data.psite) {
      site.push({
        label: this.data.psite[n]
      })
    }
    this.setData({
      site
    })
    console.log(this.data.site)
    let list = []
    for (let i in this.data.plist) {
      list.push({
        label: this.data.plist[i]
      })
    }
    this.setData({
      list,
    })
    console.log(list)

  },
  chooseStation(e) {
    console.log(e)
    let code = e.currentTarget.dataset.code
    let site = e.currentTarget.dataset.site
    let name = e.currentTarget.dataset.name
    wx.navigateTo({
      url: '/pages/index/index?code=' + code + '&site=' + site + '&name=' + name,
    })
  },
  onReady() {
    wx.hideLoading()
  },
  tabSelect(e) {
    this.setData({
      TabCur: e.currentTarget.dataset.id,
      MainCur: e.currentTarget.dataset.id,
      VerticalNavTop: (e.currentTarget.dataset.id - 1) * 50
    })
  },
  VerticalMain(e) {
    let that = this;
    let list = this.data.list;
    let tabHeight = 0;
    if (this.data.load) {
      for (let i = 0; i < list.length; i++) {
        let view = wx.createSelectorQuery().select("#main-" + list[i].id);
        view.fields({
          size: true
        }, data => {
          list[i].top = tabHeight;
          tabHeight = tabHeight + data.height;
          list[i].bottom = tabHeight;
        }).exec();
      }
      that.setData({
        load: false,
        list: list
      })
    }
    let scrollTop = e.detail.scrollTop + 20;
    for (let i = 0; i < list.length; i++) {
      if (scrollTop > list[i].top && scrollTop < list[i].bottom) {
        that.setData({
          VerticalNavTop: (list[i].id - 1) * 50,
          TabCur: list[i].id
        })
        return false
      }
    }
  },
  onShareAppMessage: function (res) {
    return {
      title: '校园充电桩小助手来了！',
      path: '/pages/user/user'
    }
  },
  onShareTimeline: function (res) {
    return {
      title: '校园充电桩小助手来了！',
      query: '123'
    }
  },
})